<?php

namespace App\Admin\Controllers\Stat;

use App\Http\Controllers\Controller;
use App\Model\Stat\StatInviteInfo;
use App\Util\ComUtil;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class StatInviteInfoController extends Controller
{
    use ModelForm;

    public function index()
    {
        $content = new Content();
        $content->header('邀请充值信息');
        $content->body($this->grid());
        return $content;
    }

    protected function grid()
    {
        $grid = new Grid(new StatInviteInfo());
        $where = [];
        $grid->model()->where($where)->orderBy('invited_num', 'desc');
        // $grid->id('记录ID');
        $grid->userProfile()->nick_name('邀请人昵称');
        $grid->userProfile()->user_profile_id('邀请人ID');
        $grid->userProfile()->avatar('邀请人头像')->display(function ($data) {
            return ComUtil::buidlImgaeHtml($data);
        });
        $grid->userProfile()->gender('性别')->display(function ($gender) {
            return $gender == 1 ? '男' : ($gender == 0 ? '女' : '-');
        });
        $grid->invited_num('被邀请人数量');
        $grid->recharge_rmb('被邀请人总充值（元）');
        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->disableActions();
        $grid->filter(function ($filter) {
            $filter->expand();
            $filter->disableIdFilter();
            $filter->column(1 / 3, function ($filter) {
                $filter->equal('userProfile.user_profile_id', '邀请人ID');
            });
        });
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableDelete();
            $actions->disableEdit();
            $actions->disableView();
        });
        return $grid;
    }
}
